<?php
class PlatnosciModel{
	
	protected function zapiszNowaTranzakcje(){
		global $config, $objSession;
		$q__ = "INSERT INTO ".PLATNOSC." (plID,plUserID,plDataWyst,plStatus,plTranIDsystem) 
			VALUES (NULL,".tools::__mres($config->plUserID).",'".date('Y-m-d H:i:s')."',1,".tools::__mres($config->plTranIDsystem).")";
		tools::__adodb('exec',$q__,true,$this->db);
		
		$plID = $this->db->lastInsertId();
		$q__ = "INSERT INTO ".PLATNSCZ." (plID,plTresc,plCena,plIlosc) 
				VALUES (".tools::__mres($plID).",".tools::__mres($config->plTresc).",
				".tools::__mres($config->plCena).",".tools::__mres($config->plIlosc).")";
		tools::__adodb('exec',$q__,true,$this->db);
		return $plID;
	}
	
	protected function listaPlatnosci($id,$typ=null){
		$q__ = "SELECT a.*, b.plTresc, b.plCena, b.plIlosc FROM ".PLATNOSC." a 
			LEFT JOIN ".PLATNSCZ." b ON b.plID = a.plID 
			WHERE a.plUserID = '{$id}' 
			AND a.plStatus = {$typ} ORDER BY a.plDataWyst";
		return tools::__adodb('getAll',$q__,true,$this->db);
		
	}
	
	protected function jednaPlatnosc($id){
		$q__ = "SELECT a.*, b.plTresc, b.plCena, b.plIlosc FROM ".PLATNOSC." a 
			LEFT JOIN ".PLATNSCZ." b ON b.plID = a.plID 
			WHERE a.plID = '{$id}'";
		return tools::__adodb('getRow',$q__,true,$this->db);
		
	}	
}